package com.kaishengit.service;


import java.util.List;

import com.kaishengit.dao.DocumentDao;
import com.kaishengit.entity.Document;
import com.kaishengit.entity.UserProject;
import com.kaishengit.util.DateUtil;
import com.kaishengit.util.Page;
import com.kaishengit.util.PkUtil;

public class DocumentService {
	private DocumentDao documentDao=new DocumentDao();
	
	public void save(String title, String content, UserProject userProject){
		Document d=new Document();
		d.setContent(content);
		d.setTitle(title);
		d.setCreatetime(DateUtil.getNowDateTime());
		d.setId(PkUtil.getId());
		d.setProject(userProject.getProject());
		d.setProjectid(userProject.getProject().getId());
		d.setUser(userProject.getUser());
		d.setUserid(userProject.getUser().getId());
		documentDao.save(d);
	}
		

	public List<Document> findByProjectId(String projectId) {
		return documentDao.findByProjectId(projectId);
	}
	
	public Document findById(String documentId){
		return documentDao.findById(documentId);
		
	}
	public Page<Document> findAll(int pageNum,String projectid) {
		Page<Document> page=new Page<Document>(3,documentDao.getCount(),pageNum);
		return documentDao.findAll(page,projectid);
	}


	public void update(String id, String title, String content) {
		documentDao.update(id,title,content);
	}


	public void del(String id) {
		documentDao.del(id);
	}

}
